﻿function communityEditGrammar(obj, songId) {
    $(obj).hide(100);
    $("#grammar-" + songId).attr("readonly", false);
    $("#saveGrammar-" + songId).show(100);
    $("#cancelGrammar-" + songId).show(100);
}

function communityCancelGrammar(obj, sId) {
    $("#saveGrammar-" + sId).hide(100);
    $(obj).hide();
    $("#editGrammar-" + sId).show(100);
    $("#grammar-" + sId).attr("readonly", true);
    $("#alertGrammar").html("");
}

function communitySaveGrammar(obj, sId) {
    var contentGrammar = $("#grammar-" + sId).val();
    $("#alertGrammar").html("<a href='/Content/Images/loader.gif'> Saving data ...");
    if (contentGrammar.length > 0) {
        $.ajax(
        {
            type: "POST",
            url: "/Song/CommunityEditGrammar",
            data: { songId: sId, content: contentGrammar },
            success: function (result) {
                if (result.Result) {
                    $.msgbox(result.Message, { type: "info" });
                    var cancelObj = document.getElementById("cancelGrammar-"+sId);
                    communityCancelGrammar(cancelObj, sId);
                }
                else {
                    $.msgbox(result.Message, { type: "error" });
                }
            }
        });
    }
    else {
        $.msgbox("It can't be empty!", { type: "info" });
    }
}